"use strict";

var EXPORTED_SYMBOLS = ["utilityViewSoso"]

Components.utils.import("resource://gre/modules/Services.jsm")
  //  const srcContentAreaUtils = "chrome://global/content/contentAreaUtils.js"
  //  Services.scriptloader.loadSubScript(srcContentAreaUtils, awin, "UTF-8")

var utilityViewSoso =
{
  getTemporaryFile : function (aURI, aContentType, acontext)
  {
    var fileLocator = Components.classes["@mozilla.org/file/directory_service;1"]
                            .getService(Components.interfaces.nsIProperties);
    var tempFile    = fileLocator.get("TmpD", Components.interfaces.nsIFile);
    var fileName    = acontext.getDefaultFileName(null, aURI, null, aContentType);
    var extension   = acontext.getDefaultExtension(fileName, aURI, aContentType);
    var leafName    = acontext.getNormalizedLeafName(fileName, extension);
        tempFile.append(leafName);
    return tempFile;
  },

    //  from viewSourceUtils.js
  element2file : function (anode, afile, acharacterSet)
  {
    const   theperm = 0x1B4; //  0664
    const   theflags= 0x02 | 0x08 | 0x20; // write | create | truncate
    // we have to convert from the source charset.
    var foStream = Components.classes["@mozilla.org/network/file-output-stream;1"]
                    .createInstance(Components.interfaces.nsIFileOutputStream);
        foStream.init(afile, theflags, theperm, 0); 
    try {
    var coStream = Components.classes["@mozilla.org/intl/converter-output-stream;1"]
                    .createInstance(Components.interfaces.nsIConverterOutputStream);
        coStream.init(foStream, acharacterSet, 0, null);
        coStream.writeString(anode);    // write the source to the file
        coStream.close();   // clean up
    }
    finally {
        foStream.close();
    }
  }    
}